<% layout('/layouts/default.html', {title: '积分发放管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i>积分发放管理
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${kjMemberJob}" action="${ctx}/kj/kjMemberJob/editIntegral" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden id="relationId" path="id"/>
				<#form:hidden name="action" id="action"/>
				<#form:hidden path="oldServiceTime" id="oldServiceTime"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('用户名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="kjMember.name"  disabled="disabled" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('活动名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="activityName" disabled="disabled" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('岗位名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="jobName" disabled="disabled" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>

					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('已发放积分')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="integrals" id="integrals" disabled="disabled" type='number' maxlength="10" class="form-control"/>
							</div>
						</div>
					</div>

					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('服务时长')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="serviceTime" id="serviceTime" type='number' min="0" maxlength="10" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('修改积分（可为负数）')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="modifyPoints" type='number' id="modifyPoints" maxlength="10" class="form-control required  number sss"/>
							</div>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required">*</span> ${text('备注(请说明修改理由)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	<div class="form-unit">${text('积分详细记录')}</div>
	<table id="dataGrid"></table>
	</div>
</div>
<% } %>
<script>
	$("#oldServiceTime").val($("#serviceTime").val());
	$('#dataGrid').dataGrid({
		url:"${ctx}/kj/kjMemberIntegralHistory/editList?relationId="+$("#relationId").val(),
		method:"post",
		columnModel: [
			{header:'${text("用户名")}', name:'kjMember.name', index:'a.member_name', width:120, align:"center"},
			{header:'${text("变动积分")}', name:'integral', index:'a.integral',width:150, align:"center"},
			{header:'${text("变动时长")}', name:'hours', index:'a.hours',width:150, align:"center"},
			{header:'${text("描述")}', name:'remarks', index:'a.remarks',width:150, align:"center"}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
	});
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
// 验证
jQuery.validator.addMethod("sss", function(value, element) {
	var tel = Number($("#modifyPoints").val()) + Number($("#integrals").val()) >= 0;
	return this.optional(element) || tel;
},"扣除积分不能大于剩余积分");
</script>
